import {install} from "@kordar/easyui-tpl";
import {defaultInitialization, i18next, loadLocalPackage, remoteLoadPkg} from '@kordar-lib/i18n'
import {initReactI18next} from 'react-i18next'
import {App} from '@kordar-lib/reducers'
import zhCnJson from "@kordar/easyui-tpl/dist/public/zh_CN.json"
import enJson from "@kordar/easyui-tpl/dist/public/en.json"
import {request} from "./util/http"

import zhCnJson2 from "../public/zh_CN.json"
import enJson2 from "../public/en.json"

let targetZhCnJson = merge({}, zhCnJson, zhCnJson2)
let targetEnJson =  merge({}, enJson, enJson2)

const i18n = i18next()
i18n.use(initReactI18next)
    .init({...defaultInitialization, debug: false, fallbackLng: "en"})
    .then(r => {})


remoteLoadPkg("zh-CN", () => {
    return new Promise((resolve, reject) => {
        resolve({"code": 200, "message": "success", "data": targetZhCnJson})
    })
})

remoteLoadPkg("en", () => {
    return new Promise((resolve, reject) => {
        resolve({"code": 200, "message": "success", "data": targetEnJson})
    })
})

import en from 'rc-easyui/dist/locale/easyui-lang-en.js'
import zhCN from 'rc-easyui/dist/locale/easyui-lang-zh_CN.js'
import {merge} from "lodash-es";

let pkgs = [
    {key: "en", value: en, name: "English"},
    {key: "zh-CN", value: zhCN, name: "简体中文"},
]

loadLocalPackage(pkgs)


let options = {}
pkgs.forEach((element) => options[element.key] = element.name);

setTimeout(() => {
    App.loadLanguageOptions(options)
}, 1000)

// ------------------

let apis = {
    adminRegister: 'admin/register',
    adminResetPassword: 'admin/reset-password',
    menus: 'menus',
    adminInfo: 'resource/admin/info',
    loginCaptcha: 'login/captcha',
    loginConfig: 'login/config',
    loginSubmit: 'login/submit',
    rbacRoles: 'rbac/roles',
    rbacAddRole: 'rbac/add-role',
    rbacUpdateRole: 'rbac/update-role',
    rbacDeleteRole: 'rbac/delete-role',
    rbacBatchDeleteRole: 'rbac/batch-delete-role',
    rbacPermissions: 'rbac/permissions',
    rbacAddPermission: 'rbac/add-permission',
    rbacUpdatePermission: 'rbac/update-permission',
    rbacDeletePermission: 'rbac/delete-permission',
    rbacBatchDeletePermission: 'rbac/batch-delete-permission',
    rbacRules: 'rbac/rules',
    rbacAddRule: 'rbac/add-rule',
    rbacDeleteRule: 'rbac/delete-rule',
    rbacGetChildren: 'rbac/get-children',
    rbacAddPermissionChildren : 'rbac/add-permission-children',
    rbacGetRolesByUser : 'rbac/get-roles-by-user',
    rbacAssignItemToUser : 'rbac/assign',
    rbacFastAddPermission : 'rbac/fast-add-permission',
    rbacGetPermissionsByUser : 'rbac/get-permissions-by-user',
}


install({
    request: request, apis: apis
})
